//
//  BaseResponse.swift
//  GoAbroad
//
//  Created by Pink Snow on 2025/5/7.
//

import UIKit

import ObjectMapper
class BaseResponse<T: Mappable>: Mappable {
    var code: Int?
    var message: String?
    var data: T?
    var success : Bool?
    
    required init?(map: Map) {}
    
    func mapping(map: Map) {
        code    <- map["code"]
        message <- map["msg"]     // ✅ 修复拼写
        data    <- map["data"]
        success <- map["success"]
    }
    
    var isSuccess: Bool {
        return code == 200
    }
    
}

class BaseArrayResponse<T: Mappable>: Mappable {
    var code: Int?
    var message: String?
    var data: [T]?
    var success: Bool?

    required init?(map: Map) {}

    func mapping(map: Map) {
        code     <- map["code"]
        message  <- map["msg"] // 注意：原本是 "msg"，不是 "message"
        data     <- map["data"]
        success  <- map["success"]
    }

    var isSuccess: Bool {
        return code == 200
    }
}

//import ObjectMapper

class BaseStatusResponse: Mappable {
    var code: Int?
    var message: String?
    var isSuccess: Bool {
        return code == 0
    }
    
    required init?(map: Map) {}
    
    func mapping(map: Map) {
        code    <- map["code"]
        message <- map["message"]
    }
}
